//
//  DHCompensateViewController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/1/28.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHCompensateViewController.h"
#import "DHReturnProductCell.h"
#import "DHReturnCluesCell.h"
#import "DHCompensate_ExplainCell.h"
#import "DHPayViewController.h"

@interface DHCompensateViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *productArr;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@end

@implementation DHCompensateViewController

- (NSArray *)productArr{
    if (!_productArr) {
        _productArr = [NSArray array];
    }
    return _productArr;
}

- (IBAction)payAction:(id)sender {
    NSArray *size = [self.dic objectForKey:@"sizes"];
    if (size.count > 0) {
        NSDictionary *sizeDic = size[0];
        float price = [[[self.dic objectForKey:@"compensate"] objectForKey:@"price"] floatValue];
        DHPayViewController *payController = [[DHPayViewController alloc] initWithPrice:@(price) order_id:[self.dic objectForKey:@"order_id"] size_id:[sizeDic objectForKey:@"_id"]];
        payController.payType = PayTypeCompensate;
        [self.navigationController pushViewController:payController animated:YES];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"损坏赔偿";
    
    self.productArr = @[self.dic];
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f元",[[[self.dic objectForKey:@"compensate"] objectForKey:@"price"] floatValue]];
    
    self.bottomView.layer.cornerRadius = 2;
    self.bottomView.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.bottomView.layer.shadowRadius = 5;
    self.bottomView.layer.shadowOpacity = 0.5;
    self.bottomView.layer.shadowOffset  = CGSizeMake(0, 0);
    
    [self.tableView registerNib:[UINib nibWithNibName:@"DHReturnProductCell" bundle:nil] forCellReuseIdentifier:kDHReturnProductCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"DHReturnCluesCell" bundle:nil] forCellReuseIdentifier:kDHReturnCluesCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"DHCompensate_ExplainCell" bundle:nil] forCellReuseIdentifier:kDHCompensate_ExplainCell];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 100 * [self.productArr count];
    }else if (indexPath.row == 1){
        return 135;
    }else{
        return 80;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        DHReturnProductCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHReturnProductCell forIndexPath:indexPath];
        [cell updateCellWithArr:self.productArr];
        return cell;
    }else if (indexPath.row == 1){
        DHReturnCluesCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHReturnCluesCell forIndexPath:indexPath];
        cell.disLabel.text = @"尊敬的用户，您好\n我们已收到您归还的商品，但根据《DRESSHERE用户使用呢协议》您需要针对此情况进行赔偿。";
        return cell;
    }else{
        DHCompensate_ExplainCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHCompensate_ExplainCell forIndexPath:indexPath];
        cell.priceLabel.text = [NSString stringWithFormat:@"赔偿金额：%.2f元",[[[self.dic objectForKey:@"compensate"] objectForKey:@"price"] floatValue]];
        cell.explainLabel.text = [NSString stringWithFormat:@"损坏说明：%@",[[self.dic objectForKey:@"compensate"] objectForKey:@"explain"]];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
